{include title="新建角色" keywords="" description=""  file='../application/admin/view/layout/header.html' /}

<body>
<div class="x-body">
    <form action="{:url('admin/admin_role/roleEdit')}" method="post" class="layui-form">
        {:token()}
        <input type="hidden" value="{$data['id']}" name="id">

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>角色名称：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" value="{$data['name']}" placeholder="请输入角色名称" id="roleName" name="name">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注：</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" value="{$data['remark']}" placeholder="请输入备注" id="" name="remark">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色状态：</label>
            <div class="layui-input-block">
                <select class="layui-input" name="status">
                        <option {if ($data['status']==1)}selected{/if} value="1">正常</option>
                        <option {if ($data['status']==0)}selected{/if} value="0">禁用</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色权限：</label>
            <div class="layui-input-block">
                {foreach $menu_tree as $k => $v}
                    {if ($v['pid']==0)}
                        <dl class="permission-list">
                            <dt>
                                <label>
                                    <input type="checkbox" lay-ignore {if ($v['selected']==1)}checked{/if} value="{$v['id']}" name="ids[]" id="user-Character-0">
                                    {$v['name']}</label>
                            </dt>
                            {foreach $menu_tree as  $vv}
                                {if ($vv['pid']==$v['id'])}
                                    <dd>
                                        <dl class="cl permission-list2">
                                            <dd>
                                                <label class="permission-list3">
                                                    　<input type="checkbox" lay-ignore {if ($vv['selected']==1)}checked{/if} value="{$vv['id']}" name="ids[]" id="user-Character-0-0">
                                                    {$vv['name']}　　
                                                </label>

                                                    {foreach $menu_tree as  $vvv}
                                                        {if ($vvv['level']>=2 && $vvv['top_id']==$vv['id'])}
                                                            <label class="permission-list3">
                                                                <input type="checkbox" lay-ignore {if ($vvv['selected']==1)}checked{/if} value="{$vvv['id']}" name="ids[]" id="user-Character-0-0-0">
                                                                {$vvv['name']}
                                                            </label>
                                                        {/if}
                                                    {/foreach}
                                            </dd>
                                        </dl>

                                    </dd>
                                {/if}
                            {/foreach}
                        </dl>
                    {/if}
                {/foreach}
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal">提交</button>
            </div>
        </div>
    </form>
</div>
<script>
    //前端验证
    var check = $("form").Validform({
        tiptype: function (msg, o) {
            if (o.type == 3) {layer.msg(msg, {icon: 2});}
        },
        ajaxPost: true,
        callback: function (data) {
            if(data.status=='y'){
                layer.msg(data.info, {icon: 1});
                setTimeout(function(){
                    parent.location.reload();
                },1000);
            }else{
                $("[name=__token__]").val(data.token);
            }
        }
    });
    check.addRule([
        {ele: "[name='name']", datatype: '*1-10', nullmsg: '请填写角色名称', errormsg: "角色名称1至10位之间"},
        {ele: "[name='remark']", datatype: '*0-30', nullmsg: '请填写备注', errormsg: "备注在0-30位之间"}
    ]);
</script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function(){
        $(".permission-list dt input:checkbox").click(function(){
            $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function(){
            var a =$(this).parent().parent().find("input:checked").length;
            var b =$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if($(this).prop("checked")){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
            }
            else{
                if(a == 0){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                }
                if(b == 0){
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                }
            }
        });

        $(".permission-list3").find("input").on('click',function () {
            if ($(this).parent().index()==0){
                $(this).prop("checked",$(this).prop("checked"));
            }else{
                if($(this).prop("checked")){
                    $(this).parent().parent().find("input:checkbox").first().prop("checked",true);
                }
            }
        })
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>